import tensorflow as tf
import numpy as np
from resmodel import Model
import scipy.io as scio

filenames=[]
labelnum=[]
dstnum=['94','134','135','95','16']#B3
f = open("./IndexFiles/LstTrain")
lines = f.readlines()
for line in lines:
    cur = line.split(' ')[0]
    if cur in dstnum:
        labelnum.append(cur)
        filenames.append(line.split(' ')[1].replace("\n",""))
label = []
temp = []
cnt = 0
for i in labelnum:
    if i not in temp:
        temp.append(i)
        cnt+=1
    label.append(cnt-1)


for i,k in enumerate(filenames):
    filenames[i] = r"./SFootBD2/" + k + r".mat"

#filenames[] 对应 label[]

input_train=[]
for i in filenames:
    left = []
    right = []
    data = scio.loadmat(i)
    for i in range(100,200):
        left.append(np.append(data['yl'][i],np.array([0,0,0])).reshape(13,7))
        right.append(np.append(data['yr'][i],np.array([0,0,0])).reshape(13,7))
    com = np.concatenate((left,right),axis=2)
input_train.append(com.reshape(13,14,100))
#print(len(input_train),len(input_train[0]),len(input_train[0][0]),len(input_train[0][0][0]))
#200 100 13 14
# model = Model()
# model.compile(optimizer=tf.keras.optimizers.Adam(1e-3),loss=tf.keras.losses.categorical_crossentropy,metrics=['accuracy'])
# label = np.float32(tf.keras.utils.to_categorical(label,num_classes=5))
# batch_size = 64
# train_dataset = tf.data.Dataset.from_tensor_slices((input_train,label)).batch(batch_size).shuffle(batch_size*10)
# model.fit(train_dataset,epochs=5)
# model.save("./saver/b3_200_noimp_model.h5")






